<?php 

require "../gobal.php";

function doSubmit(){



	$issue_ids=$_POST["PlanIdList"];
    $device_id=$_POST["VersionId"];
    $device_color=$_POST["DeviceColor"];
    //$service_method=$_POST["OrderType"]=="phonefix"?"express":"visit";
    $service_method=$_POST["ServiceType"]=="1"?"visit":"express";
    $visit_contact_id=$_POST["UserAddressId"];
    $visit_arrive_at=$_POST["ComeTime"];
	$PayCheckoutType=$_POST["PayCheckoutType"];
    $PayCheckoutInfo=$_POST["PayCheckoutInfo"];
    $express_code=$_POST["PostId"];
    $PostInfo=$_POST["PostInfo"];
	$express_sender_name=$_POST["PostName"];
	$express_sender_address=$_POST["PostAddress"];
    $express_sender_tel=$_POST["PostCallPhone"];
	$remark=$_POST["remark"];

	//$remark = iconv("utf-8","gbk",$remark);

	$ordercode="xxxx";
	$customer_id=0;
	$total_price=$_POST["total_price"];
	//$visit_address_id=0;

	$sql="INTO `order_sum`(`remark`, `code`, `created_at`, `customer_id`, `device_id`, `device_color`, `total_price`, `pay_stats`, `service_method`, `express_code`, `express_sender_name`, `express_sender_address`, `express_sender_tel`, `visit_contact_id`, `visit_arrive_at`) VALUES ";

	$sql=$sql."('$remark',UNIX_TIMESTAMP(),NOW(),$customer_id,$device_id,'$device_color',$total_price,0,'$service_method','$express_code','$express_sender_name','$express_sender_address','$express_sender_tel',$visit_contact_id, '$visit_arrive_at')";

	$orderId=insert_row($sql);

    $sql="INTO `order_item`( `order_id`, `issue_id`, `issue_price`, `issue_name`) select $$orderId,di.id,di.repair_amount,di.name from device_issue di WHERE di.id in ($issue_ids)";

	$msg="";
	$success='false';
	insert_row($sql);

	if($orderId>0){
       $success='true';
	}



    echo "{ success:$success,orderId:$orderId,msg:'$msg',remark:'$remark'}";
	//echo "{orderId:$orderId,msg:'$msg',success:$success}";
    
}





header("Content-type: application/json; charset=utf-8"); 

$action=$_GET["action"] ;



switch($action){

	case "doSubmit": doSubmit();break;

	default : break;

}



?>